// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.ui.web.browser.dom;

import org.dengues.ui.i18n.Messages;
import org.eclipse.swt.internal.ole.win32.IDispatch;

/**
 * An <code>Document</code> is the root of the HTML hierarchy and holds the entire content. Besides providing access
 * to the hierarchy, it also provides some convenience methods for accessing certain sets of information from the
 * document.
 * <p>
 * See also org.w3c.dom.html.HTMLDocument
 * 
 * @author jliu
 */
public class HTMLDocument extends Node {

    public HTMLDocument(IDispatch dispatch, DocumentContext context) {
        super(dispatch, context);
    }

    /**
     * The element that contains the content for the document. In documents with <code>BODY</code> contents, returns
     * the <code>BODY</code> element. In frameset documents, this returns the outermost <code>FRAMESET</code>
     * element.
     */
    public HTMLElement getBodyElement() {
        return (HTMLElement) context.getNode(getDispatchProperty("body")); //$NON-NLS-1$
    }

    /**
     * All children of the HTML hierarchy.
     */
    public NodeList getAll() {
        return context.getNodeList(getDispatchProperty("all")); //$NON-NLS-1$
    }

    /**
     * Document is the root node of HTML hierarchy, so its parent is null.
     * 
     * @see com.zabidoo.extension.dom.Node#getParentNode()
     */
    public Node getParentNode() {
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.internal.ole.win32.IUnknown#Release()
     */
    public int Release() {
        int r = super.Release();
        if (r <= 0) {
            System.err.println("HTMLDocument freed"); //$NON-NLS-1$
        }
        return r;
    }
}
